"use strict";
Page({
    data: {
        allIn: false, money: 0,
        shopping: [
            {
                id: 1,
                title: '现货发顺丰 6期免息',
                name: 'vivo x62 4G 新品拍照',
                num: 1,
                price: 158.00,
                checked: false
            },
            {
                id: 2,
                title: '现货发顺丰 6期免息',
                name: 'vivo x60 5G 新品拍照',
                num: 2,
                price: 138.00,
                checked: false
            },
            {
                id: 3,
                title: '现货发顺丰 6期免息',
                name: 'vivo x60 5G 新品拍照',
                num: 3,
                price: 3538.22,
                checked: false
            },
            {
                id: 4,
                title: '现货发顺丰 6期免息',
                name: 'vivo x60 5G 新品拍照',
                num: 3,
                price: 3538.22,
                checked: false
            },
            {
                id: 5,
                title: '现货发顺丰 9期免息',
                name: 'vivo x61 5G 新品拍照',
                num: 3,
                price: 3538.22,
                checked: false
            }
        ],
        cart: [
            {
                img: '',
            }
        ]
    },
    showMoney: function () {
        console.log(66);
        console.log(this.data.money);
    },
    onLoad: function () {
        var that = this;
        var sum = 0;
        for (var i = 0; i < that.data.shopping.length; i++) {
            if (that.data.shopping[i].checked) {
                sum += (that.data.shopping[i].price * that.data.shopping[i].num);
            }
        }
        that.setData({
            money: sum
        });
    },
    myevent: function (e) {
        var that = this;
        var sum = 0;
        var data = that.data.shopping;
        var _a = e.detail.params, id = _a.id, checked = _a.checked;
        for (var a = 0; a < data.length; a++) {
            if (data[a].id == id) {
                data[a].checked = checked;
            }
            if (data[a].checked) {
                sum += (data[a].price * data[a].num);
            }
        }
        that.setData({
            money: sum
        });
    },
    handlerName: function () {
        var that = this;
        var sum = 0;
        for (var i = 0; i < that.data.shopping.length; i++) {
            that.data.shopping[i].checked = (!that.data.allIn);
            if (that.data.shopping[i].checked) {
                sum += (that.data.shopping[i].price * that.data.shopping[i].num);
            }
        }
        that.setData({
            shopping: that.data.shopping,
            allIn: (!that.data.allIn), money: sum
        });
    }
});
